#pragma once

#include "logger_api.hpp"
#include <string>
#include <chrono>
#include <nlohmann/json.hpp>
#include <memory>
#include <filesystem>


// 日志级别配置
struct LogLevelConfig {
    LogLevel default_level = LogLevel::Info;
};

// 异步工作线程配置
struct AsyncConfig {
    size_t main_queue_size = LoggerConstants::DEFAULT_MAIN_QUEUE_SIZE;
    size_t fallback_queue_size = LoggerConstants::DEFAULT_FALLBACK_QUEUE_SIZE;
    std::chrono::milliseconds flush_interval = LoggerConstants::DEFAULT_FLUSH_INTERVAL;
    float queue_space_threshold = LoggerConstants::DEFAULT_QUEUE_SPACE_THRESHOLD;
    size_t fallback_batch_size = LoggerConstants::DEFAULT_FALLBACK_BATCH_SIZE;
};

// 控制台输出配置
struct ConsoleSinkConfig {
    bool enabled = true;
    std::string logger_name = "my_app_console";
    bool apply_filtering = false;
};

// 文件输出配置
struct FileSinkConfig {
    bool enabled = false;
    std::string filename = "log/application.log";
    size_t max_size = LoggerConstants::DEFAULT_MAX_FILE_SIZE;
    size_t max_files = LoggerConstants::DEFAULT_MAX_FILES;
    std::string logger_name = "my_app_file";
};

// 网络输出配置
struct NetworkSinkConfig {
    bool enabled = false;
    std::string url = "http://localhost:8080/log";
    long timeout = LoggerConstants::DEFAULT_NETWORK_TIMEOUT;
    long connect_timeout = LoggerConstants::DEFAULT_CONNECT_TIMEOUT;
    size_t thread_pool_size = 4;
};

// 过滤器配置
struct FilterConfig {
    bool enabled = false;
    std::vector<std::pair<std::string, std::string>> filters = {
        {"\"password\"\\s*:\\s*\"[^\"]+\"", "\"password\": \"******\""},
        {"\"token\"\\s*:\\s*\"[a-zA-Z0-9]{20,}\"", "\"token\": \"[REDACTED]\""}
    };
    bool default_filters_cleared = false;
};

// 回溯配置
struct BacktraceConfig {
    bool enabled = false;
    size_t size = LoggerConstants::DEFAULT_BACKTRACE_SIZE;
};

// 格式化器配置
struct FormatterConfig {
    enum class Type { Basic, JSON } type = Type::JSON;
};     

// metrics 设置
struct MetricsConfig {
    bool enabled = false;
};


// 完整的日志配置
struct LoggerConfig {
    LogLevelConfig level;
    AsyncConfig async;
    ConsoleSinkConfig console;
    FileSinkConfig file;
    NetworkSinkConfig network;
    FilterConfig filter;
    BacktraceConfig backtrace;
    FormatterConfig formatter;
    MetricsConfig metrics = {false};
    std::string logger_name = "default";
    // 从JSON文件加载配置
    static LoggerConfig fromJsonFile(const std::string& filepath);
    
    // 从JSON字符串加载配置
    static LoggerConfig fromJsonString(const std::string& json_str);
    
    // 导出为JSON
    nlohmann::json toJson() const;
};

